#!/bin/bash
DLDITOOL=$(which dlditool)
DLDIPATCHDIR=$HOME/data

dldiFiles=$(for i in ${DLDIPATCHDIR}/*.dldi ; do  basename  $i .dldi ; done)

if [[ ! -e "$DLDITOOL" ]] ; then
  zenity --error --text "Could not find dlditool in the PATH $DLDITOOL"
  exit 1
fi

for arg in ${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS}
do
  patch=$(zenity --list --text "Patch with dlditool?" --list --column "Patch Type" ${dldiFiles})
  result=$?
  if [[ $result == 0 ]] ; then
    patchFile=${DLDIPATCHDIR}/${patch}.dldi
    if [[ -e ${patchFile} ]] ; then
      text=$(${DLDITOOL} ${patchFile} "${arg}")
      zenity --text "$text" --info
    else
      zenity --error --text "Could not find $patchFile"
    fi
  fi
done
